package com.itheima.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.dubbo.dao.UserDao;
import com.itheima.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {
    @Autowired
    private UserDao userDao;

    //根据手机号码查询用户
    public User findByMobile(String mobile) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile", mobile);
        return userDao.selectOne(qw);
    }

    public Long save(User user) {
        userDao.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
        userDao.updateById(user);
    }

    @Override
    public User findById(Long userId) {
        return userDao.selectById(userId);
    }

    @Override
    public User findhuanxin(String hunaxinId) {
        LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery(User.class);
        lqw.eq(User::getHxUser, hunaxinId);
        User user = userDao.selectOne(lqw);
        return user;
    }


}
